var mysql = require('mysql');
var express = require('express');
var app = express();
var connection = mysql.createConnection({
  host: '127.0.0.1',
  port: '3306',
  user: 'root',
  password: 'admin',
  database: 'db_word'
})
connection.connect();
var selectSql = "select translation from enwords where word = '";
var str = '';

app.get('/word', function(req, res) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  var [ left, right ] = req.url.split('=');
  selectSql2 = selectSql + right + "'";
  connection.query(selectSql2, function(err, result){
    selectSql2 = selectSql;
    if(err)
      console.log('SELECT ERROR:' + err);
    str = JSON.stringify(result);
    console.log(str);
    res.send(str);
  });

});

app.listen(5000, function(){
  console.log("Server running at 4000 port");
})